<%- include header %>
<!-- 主题内容start -->
<table class="table table-bordered table-striped table-condensed table-hover">
    <tr>
        <th class="span3" colspan="5"><h4 style="text-align: center">活动(活动总数：<%- count %>个|当前页：<%- page.num %>/<%- page.pageCount %>页)</h4></th>
    </tr>
    <tr>
        <th class="">主题</th>
        <th class="">活动时间</th>
        <th class="">活动详情</th>
        <th class="">参与人数</th>
        <th class="span3">操作</th>
    </tr>
    <% datas.forEach(function(data,index){ %>
    <tr>
        <td>
            <%- data.theme %>
        </td>
        <td>
            <%- data.activeDate %>
        </td>
        <td>
            <a id="t<%- data._id %>">活动详情/编辑</a>
            <div id="win<%- data._id %>" iconCls="icon-save" >
                <div style="width: 50%;float: left">
                    <form class="form-horizontal registerform" action="/manager/activeEdit" method="post">
                        <input type="hidden" name="id" value="<%-data._id %>">
                        <fieldset>
                            <legend>活动详情</legend>

                            <div>
                                <div class="control-group">
                                    <table>
                                        <tr>
                                            <td>
                                                <label class="control-label"><span class="need" style="width:10px;">*</span> 活动名称</label>
                                            </td>
                                            <td>
                                                <input value="<%- data.theme%>" type="text" class="inputxt"  name="theme" datatype="*3-18" errormsg="名称至少3个字符,最多18个字符！">
                                            </td>
                                            <td style="padding-top: 10px">
                                                <span class="Validform_checktip"></span>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                                <div class="control-group">
                                    <table>
                                        <tr>
                                            <td>
                                                <label class="control-label"><span class="need" style="width:10px;">*</span> 活动时间</label>
                                            </td>
                                            <td>
                                                <input value="<%- data.activeDate%>" type="text" class="inputxt"  name="activeDate" datatype="*6-30" onclick="WdatePicker()">
                                            </td>
                                            <td style="padding-top: 10px">
                                                <span class="Validform_checktip"></span>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                                <div class="control-group">
                                    <table>
                                        <tr>
                                            <td>
                                                <label class="control-label"><span class="need" style="width:10px;">*</span> 活动地点</label>
                                            </td>
                                            <td>
                                                <input value="<%- data.addr%>" type="text" class="inputxt"  name="addr" datatype="*3-20" errormsg="请输入正确的地点！">
                                            </td>
                                            <td style="padding-top: 10px">
                                                <span class="Validform_checktip"></span>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                                <div class="control-group">
                                    <table>
                                        <tr>
                                            <td>
                                                <label class="control-label"><span class="need" style="width:10px;">*</span>&nbsp;&nbsp;&nbsp;&nbsp;主办方</label>
                                            </td>
                                            <td>
                                                <input value="<%- data.sponsor%>" type="text" class="inputxt"  name="sponsor" datatype="*3-20" errormsg="主办方为3-20个字符！">
                                            </td>
                                            <td style="padding-top: 10px">
                                                <span class="Validform_checktip"></span>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                                <div class="control-group">
                                    <table>
                                        <tr>
                                            <td>
                                                <label class="control-label"><span class="need" style="width:10px;">*</span> 活动语言</label>
                                            </td>
                                            <td>
                                                <select name="language" datatype="*" nullmsg="请选择语言！" errormsg="请选择语言！">
                                                        <option value="">请选择</option>
                                                        <% plateDatas.forEach(function(plateData,index){%>
                                                        <% if(data.language==plateData.platename){%>
                                                        <option value="<%- plateData.platename%>" selected="selected"><%- plateData.platename%></option>
                                                        <% }else{%>
                                                        <option value="<%- plateData.platename%>"><%- plateData.platename%></option>
                                                        <%}%>
                                                        <% })%>
                                                </select>
                                            </td>
                                            <td style="padding-top: 10px">
                                                <span class="Validform_checktip"></span>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                                <div class="control-group">
                                    <table>
                                        <tr>
                                            <td>
                                                <label class="control-label"><span class="need" style="width:10px;">*</span> 活动费用</label>
                                            </td>
                                            <td>
                                                <input value="<%- data.cost%>" type="text" class="inputxt"  name="cost" datatype="n1-4" errormsg=金额只能为0-1000的数字>
                                            </td>
                                            <td style="padding-top: 10px">
                                                <span class="Validform_checktip"></span>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </div>

                            <div class="control-group">
                                <label class="control-label" for="password">活动简介</label>
                                <div class="controls">
                                    <!--<textarea rows="10" style="width: 540px" id="k1" name=""></textarea>-->
                                    <script id="container1<%- data._id %>" name="intro" type="text/plain"><%- data.intro%></script>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="password">详细信息</label>
                                <div class="controls">
                                    <!--<textarea rows="10" style="width: 540px" id="k1" name=""></textarea>-->
                                    <script id="container<%- data._id %>" name="discribe" type="text/plain"><%- data.discribe%></script>
                                </div>
                            </div>
                            <div class="form-actions">
                                <button type="submit" class="btn btn-primary ">提交</button>
                            </div>
                        </fieldset>
                    </form>
                </div>
                <div style="width: 180px;height:230px;float: left;margin-left: 50px;border: 1px dotted #9f9d93;position: relative;margin-top: 80px">
                    <img id="img_poster<%-  data.id %>" src="<%-  data.poster %>" style="width: 180px;height: 230px">
                    <div class="circular" style="position: absolute;top:90px;left:25px;z-index:10;text-align:center;line-height: 20px;width:130px;height: 40px;background-color: #d77a03;">
                        <h4 style="color: white;line-height: 20px">海报预览</b></h4>
                    </div>
                    <div class="file-box" style="margin-top: 20px">
                        <form  method="post" enctype="multipart/form-data">
                            <input type='text' name='textfield' id='textfield<%- data._id%>' class='txt' style="margin-bottom: 0px"/>
                            <input type='button' class='btn' value='浏览...' />
                            <input type="file" name="file" class="file" id="fileToUpload<%- data._id%>" size="20" onchange="document.getElementById('textfield<%- data._id%>').value=this.value" />
                            <input type="submit" name="submit" class="btn" value="上传" onclick="return ajaxFileUpload('<%- data._id%>');"/>
                        </form>
                    </div>
                </div>
            </div>
        </td>
        <td>
            <a href="/manager/applyUsers?id=<%- data._id %>"><span><%- data.applyNum %>人(点击查看详情)</span>
        </td>
        <td>
            <a class="btn btn-danger btn-small" onclick="goDelete('<%- data._id %>')">删除活动</a>
            <!--<a href="#toPost<%-data._id%>"  class="btn btn-warning btn-small" onclick="toPost('<%-data._id%>')">关联帖子</a>-->
        </td>
    </tr>

    <script>
        $('#win<%- data._id %>').window({
            title: '菜单',
            width: 1111,
            modal: true,
            shadow: true,
            closed: true,
            maximizable : false,
            height: 450,
            resizable:true
        });

        $("#t<%- data._id %>").click(function(){

            $('#win<%- data._id %>').window('open');
        })

    </script>
    <% }) %>
</table>

<hr>

<div class="span12">
    <div id="page1"></div>
</div>
<!-- 主题内容end -->
<%- include footer %>
<script>
    function toPost(id){
        $.fancybox({//调用fancybox弹出层
            'type':'ajax',
            'href':'/manager/toPost?id='+id
        });
    }
    function goDelete(id){
        var prompt=confirm("你确定删除该活动吗？？");

        if(prompt){

            window.location.href="/manager/delActive?id="+id;
        }
    }
    function test(){
//        alert($(window).height())       //可见区域高度
//        alert($(window).width())        //可见区域宽度
//        alert($(document).height())     //整个页面高度
//        alert($(document).width())      //整个页面宽度
        alert($(document).scrollTop())  //获取滚动条到顶部的垂直高度
    }
    $(function(){
        //获得浏览器参数

        $.extend({
            getUrlVars: function(){
                var vars = [];
                var hash;
                var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
                console.log(hashes);
                for(var i = 0; i < hashes.length; i++){
                    hash = hashes[i].split('=');
                    vars.push(hash[0]);
                    vars[hash[0]] = hash[1];
                }
                return vars;
            },
            getUrlVar: function(name){
                return $.getUrlVars()[name];
            }
        });

        //封装浏览器参数
        var composeUrlParams=function(){
            var param='';
            $.each($.getUrlVars(), function(i, item) {
                if(item!='num'){
                    var val=$.getUrlVar(item);
                    if(val) param += "&" + item+"="+val;
                }
            });
            return param;
        }
        var options = {
            currentPage:<%- page.num %>,                //当前页，css样式同其他页不同
            totalPages:<%- page.pageCount %>,           //总页数
            numberOfPages:5,                            //导航最多显示页数
            pageUrl: function(type, page, current) {    //页面跳转
                if(page!=<%- page.num %>){
                    return "/manager/active?num="+ page+composeUrlParams();
                }

            }
        }
        $('#page1').bootstrapPaginator(options);
    })
    <% datas.forEach(function(data,index){%>
    var ue = UE.getEditor('container<%- data._id %>',{
        initialFrameWidth:650,
        enableAutoSave:false,
        initialFrameHeight:171,
        saveInterval:60000
    });
    var ue = UE.getEditor('container1<%- data._id %>',{
        initialFrameWidth:650,
        enableAutoSave:false,
        initialFrameHeight:100,
        saveInterval:60000
    });
    <% }) %>

</script>
<script type="text/javascript">
    $(function(){
        //$(".registerform").Validform();  //就这一行代码！;

        $(".registerform").Validform({
            tiptype:2
        });
    })
    function ajaxFileUpload(id) {

        $.ajaxFileUpload({
            url : '/manager/uploadPoster',// servlet请求路径
            secureuri : false,
            fileElementId : 'fileToUpload'+id,// 上传控件的id
            dataType:'text',
            success : function(data) {
                //alert(data);
                //alert(data.replace(/<.*?>/ig,''));

                if(data.indexOf('url')<0){
                    alert(data.replace(/<.*?>/ig,''));
                }
                eval("var jsobjjson="+data.replace(/<.*?>/ig,''));
                //alert(decodeURIComponent(jsobjjson.url))

                if(jsobjjson.state=='上传成功'){
                    //alert('111')
                    $("#img_poster"+id).attr("src",decodeURIComponent(jsobjjson.url));
                }
            },
            error : function(data, status, e) {
                alert('上传出错');
            }
        })

        return false;

    }
</script>


